package com.mls.guardian.executor.slave;

import com.mls.guardian.appst.chain.TaskResult;
import com.mls.guardian.common.RemoteUtil;
import com.mls.guardian.container.SlaveContainer;
import com.mls.guardian.dataobj.ServerProcessInfo;
import com.mls.guardian.em.ContainerRole;
import com.mls.guardian.protocol.RemoteBody;
import com.mls.guardian.protocol.RemoteCommand;
import com.mls.guardian.protocol.body.AppRestartBody;
import com.mls.guardian.remoting.executor.RemoteExecutor;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * Created by root on 15-12-7.
 */
public class SlaveUpgradeExecutor implements RemoteExecutor {
    private static final Logger log = LoggerFactory.getLogger(SlaveRestartAppExecutor.class);
    private SlaveContainer container;

    public SlaveUpgradeExecutor(SlaveContainer container) {
        this.container = container;
    }

    @Override
    public RemoteBody execute(ChannelHandlerContext ctx, RemoteCommand request) throws Exception {
        AppRestartBody appRestart = (AppRestartBody) request.getRemoteBody();


        log.info("slave 收到Upgrade Guardian请求,请求id是[{}],version[{}]", request.getRequestId(), appRestart.getVersionTag());

        TaskResult taskResult = container.getAppController().upgrade(ContainerRole.SLAVE, appRestart.getVersionTag());

        appRestart.setSuc(taskResult.isSuc());
        return appRestart;
    }
}